﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchEdu.Framework.Win;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Algorithm;
using SchEdu.Framework.Objective;

namespace SchEduApp
{
    public partial class GanttForm : Form
    {
        GanttGrid jobGanttGrid = new GanttGrid();
        GanttGrid machineGanttGrid = new GanttGrid();
        MachineUtilizationChart machineUtilizationChart = new MachineUtilizationChart();
        MachineUtilizationPercentageChart machineUtilizationPercentageChart = new MachineUtilizationPercentageChart();
        SchEduDataSet.SolutionRow solution;

        public SchEduDataSet.SolutionRow Solution
        {
            get { return solution; }
            set { solution = value; }
        }

        public GanttForm()
        {
            InitializeComponent();


            jobGanttTab.Controls.Add(jobGanttGrid);
            jobGanttGrid.Dock = DockStyle.Fill;
            machineGanttTab.Controls.Add(machineGanttGrid);
            machineGanttGrid.Dock = DockStyle.Fill;
            utilizationTab.Controls.Add(machineUtilizationChart);
            machineUtilizationChart.Dock = DockStyle.Fill;
            utilizationPercentageTab.Controls.Add(machineUtilizationPercentageChart);
            machineUtilizationPercentageChart.Dock = DockStyle.Fill;

        }

        private void aboutAlgorithmButton_Click(object sender, EventArgs e)
        {
            AboutForm aboutForm = new AboutForm();
            AboutInfo aboutInfo = new AboutInfo();
            aboutInfo.Title = solution.Title;
            aboutInfo.Company = solution.Company;
            aboutInfo.Copyright = solution.Copyright;
            aboutInfo.Description = solution.Description;
            aboutInfo.Product = solution.Product;
            aboutInfo.Version = solution.Version;
            aboutForm.SetAboutInfo(aboutInfo);
            aboutForm.ShowDialog();
        }

        private void GanttForm_Load(object sender, EventArgs e)
        {
            this.Text = solution.Title;

            performanceBindingSource.DataSource = solution.GetPerformanceRows();
            allocationBindingSource.DataSource = solution.GetAllocationRows(); ;

            jobGanttGrid.DisplayChart(GanttGridType.Order, SchEduAppContext.SchEduData, solution);
            machineGanttGrid.DisplayChart(GanttGridType.Machine,SchEduAppContext.SchEduData, solution);
            machineUtilizationChart.DisplayChart(SchEduAppContext.SchEduData, solution);
            machineUtilizationPercentageChart.DisplayChart(SchEduAppContext.SchEduData, solution);

        }

        private void objectiveAlgorithmButton_Click(object sender, EventArgs e)
        {
            DataGridViewRow dgvr = this.objectiveDataGridView.CurrentRow;
            if (dgvr == null)
            {
                return;
            }
            DataRowView drv = dgvr.DataBoundItem as DataRowView;
            if (drv == null)
            {
                return;
            }

            SchEduDataSet.PerformanceRow performance = drv.Row as SchEduDataSet.PerformanceRow;
            if (performance == null)
            {
                return;
            }

            AboutForm aboutForm = new AboutForm();
            AboutInfo aboutInfo = new AboutInfo();
            aboutInfo.Title = performance.Title;
            aboutInfo.Company = performance.Company;
            aboutInfo.Copyright = performance.Copyright;
            aboutInfo.Description = performance.Description;
            aboutInfo.Product = performance.Product;
            aboutInfo.Version = performance.Version;
            aboutForm.SetAboutInfo(aboutInfo);
            aboutForm.ShowDialog();
        }
    }
}
